class Solution {//leetcode25——k个一组翻转链表
public:
    ListNode* reverseKGroup(ListNode* head, int k) {
        ListNode*cur=head;
        for(int i=1;i<k;i++) {
            if(cur==nullptr) return head;
            cur=cur->next;
        }
        if(cur==nullptr) return head;
        ListNode* remainer=cur->next;
        remainer=reverseKGroup(remainer,k);
        cur->next=remainer;
        ListNode newhead;   //头结点
        cur=head;
        while(cur!=remainer){
            ListNode* next=cur->next;
            cur->next=newhead.next;
            newhead.next=cur;
            cur=next;
        }
        head->next=remainer;
        return newhead.next;
    }
};